package com.paziy.notes.core;

/**
 * Beats per minute or speed of composition.
 *
 * @author thecederick@gmail.com (Paziy Evgeniy)
 * @version 0.2
 * @since 1.0 (27.11.13 18:26)
 */
public class Temp {
    //todo must be saved to some data holder like default values maybe xlm in resource folder
    /**
     * Default temp value. Used for default constructor.
     */
    protected static final short DEFAULT_TEMP = 120;

    /**
     * Min allowed value of temp. Used in checkTempValue method
     */
    protected static final short MIN_TEMP = 10;

    /**
     * Max allowed value of temp. Used in checkTempValue method
     */
    protected static final short MAX_TEMP = 500;

    private short tempValue;

    /**
     * Default constructor creates Temp with default value
     */
    public Temp() {
        tempValue = DEFAULT_TEMP;
    }

    /**
     * Creates Temp with user value of temp.
     * Can throw RuntimeException if tempValue is illegal
     * For see diapason range {@see Temp#checkTempValue}
     *
     * @param tempValue value of created temp
     */
    public Temp(short tempValue) {
        checkTempValue(tempValue);

        this.tempValue = tempValue;
    }

    /**
     * Getter for temp value
     *
     * @return current value of temp
     */
    public short getTempValue() {
        return tempValue;
    }

    /**
     * Setter for emp value
     * Can throw RuntimeException if newTempValue is illegal
     *
     * @param newTempValue new value of temp
     */
    public void setTempValue(short newTempValue) {
        checkTempValue(newTempValue);

        tempValue = newTempValue;
    }

    /**
     * Returns a string representation of the object.
     *
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return Short.toString(tempValue) + "bpm";
    }

    /**
     * Checks temp value for allowed diapason
     * Allowed from 1 to 32767 (max value is too big and min value is too low)
     *
     * @param tempValue
     */
    private static void checkTempValue(short tempValue) {
        if (tempValue < MIN_TEMP || tempValue > MAX_TEMP) throw new RuntimeException("wrong Temp value");
    }
}
